package com.example.kkblog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.kkblog.domain.DailyCheck;
import com.example.kkblog.domain.dto.UserDto;
import com.example.kkblog.domain.query.DailyCheckQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author xiaoke
 * @Date 2024 06 02 00 11
 **/
@Repository
@Mapper
public interface DailyCheckMapper extends BaseMapper<DailyCheck> {
    // 查询用户今日是否签到
    @Select("SELECT d.* " +
            "FROM `user` u, daily_check d " +
            "WHERE d.check_day=#{checkDay} and u.id=d.user_id and d.user_id=#{userId}")
    DailyCheck selectUserCheck(DailyCheckQuery query);

    // 获取签到排行榜
    @Select("SELECT u.*,d.create_time as checkTime " +
            "FROM `user` u, daily_check d " +
            "WHERE d.check_day=#{checkDay} and u.id=d.user_id " +
            "ORDER BY d.id ASC " +
            "LIMIT #{pageSize} ")
    List<UserDto> selectCheckUsers(DailyCheckQuery query);
}
